package com.bj58.mis.apm.server.statistics.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author: zhangfx
 * @create: 2018-07-04 10:30
 **/
@Component
public class RequestContext {
    private static ThreadLocal<LoginUser> loginUserThreadLocal = new ThreadLocal<>();

    @Value("${roc.auth.enable:false}")
    private boolean authEnable;

    @Value(("${roc.auth.testUserName:}"))
    private String testUserName;
    @Value(("${roc.auth.testIsAdmin:true}"))
    private boolean testIsAdmin;


    public void setLoginUser(LoginUser loginUser){
        loginUserThreadLocal.set(loginUser);

    }
    public LoginUser getLoginUser(){
        LoginUser loginUser = loginUserThreadLocal.get();
        if(loginUser==null && !authEnable){
            return new LoginUser(testUserName, testIsAdmin);
        }
        return loginUser;
    }
}
